---
title: "Misinformation among Migrants - Replication"
author: "Daniel Rojas"
date: "`r Sys.Date()`"
output: pdf_document
---


This document replicates the results from Bandiera and Rojas, *Misinformation among Migrants: Evidence from Mexico and Colombia*, including main results and results reported in the online Appendix. The results are reported in the order in which they appear in the manuscript and Appendix. The data used to reproduce the results is available in the Journal of Experimental Political Science Dataverse.

- Software: RStudio Version 2024.09.1+394 (2024.09.1+394)

- Computer specification: MacBook Air (M1, 2020), macOS Monterey, chip Apple M1, memory 16 GB.

- Contact: danielrojaslozano@gmail.com

```{r setup, include=FALSE}

knitr::opts_chunk$set(
  warning = FALSE,
  message = FALSE
)

# Function to install or load packages
install_and_load = function(packages) {
        for (pkg in packages) {
                if (!requireNamespace(pkg, quietly = TRUE)) {
                        install.packages(pkg, dependencies = TRUE)
                }
                library(pkg, character.only = TRUE)
        }
}

# Install/load packages
install_and_load(c('tidyverse',
                   'estimatr',
                   'patchwork',
                   'foreach',
                   'texreg',
                   'ggrepel',
                   'kableExtra',
                   'car',
                   'modelsummary'))

`%notin%` = Negate(`%in%`)

# load clean data
dt_mexico = readRDS('clean_data_MX.rds')
dt_colombia = readRDS('clean_data_COL.rds')


```


# Manuscript 

```{r regressions_MX}

# Misinformation
misinfo_outcomes = c('trust_sources_index_binary','accuracy_rate_e',
                     'verification_tendency_rate_e',
                     'accuracy_verification_tendency_rate_e',
                     'dissemination_f_e','dissemination_r_e',
                     'trust_newspaper_binary','trust_gov_binary','trust_fb_binary',
                     'trust_tt_binary','trust_twitter_binary','trust_wa_binary',
                     'accuracy_discernment_e','sharing_discernment_e',
                     'a_ratings_true_e','a_ratings_false_e')
misinfo_binary = paste0("%s ~ misinformation_treatment")
## Regressions
misinfo_binary_out = foreach(i = 1:length(misinfo_outcomes), .combine = "rbind") %do% {
    # Format formulas
    outcome = misinfo_outcomes[i]
    main_out = sprintf(misinfo_binary, outcome)

    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_mexico)

    # Tidy and return
    out = bind_rows(tidy(reg_full, conf.int=TRUE))
    return(out)
}

# Cybersecurity
cs_risk = lm_robust(online_risk_index_binary_e ~ cybersecurity_treatment 
                    + online_risk_index_binary_b, dt_mexico) %>% tidy
cs_risk_0 = lm_robust(online_risk_index_binary_e ~ cybersecurity_treatment,
                      dt_mexico) %>% tidy
cs_measures = lm_robust(safety_measures_e ~ cybersecurity_treatment, dt_mexico) %>% tidy
cs_treatment_out = bind_rows(cs_risk, cs_measures)


## Models with pre-treatment outcomes
misinfo_outcomes2 = misinfo_outcomes[!grepl("^trust", misinfo_outcomes)]
baseline_outcomes2 = c('accuracy_rate_b',
                       'verification_tendency_rate_b',
                       'accuracy_verification_tendency_rate_b',
                       'dissemination_f_b',
                       'dissemination_r_b',
                       'accuracy_discernment_b',
                       'sharing_discernment_b',
                       'a_ratings_true_b',
                       'a_ratings_false_b')

misinfo_binary2 = paste0("%s ~ misinformation_treatment + %s")

## Regressions
misinfo_binary_out2 = foreach(i = 1:length(misinfo_outcomes2), .combine = "rbind") %do% {
    # Format formulas
    outcome = misinfo_outcomes2[i]
    control = baseline_outcomes2[i]
    main_out = sprintf(misinfo_binary2, outcome, control)

    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_mexico)

    # Tidy and return
    out = bind_rows(tidy(reg_full, conf.int=TRUE))
    return(out)
}


## Models without controlling for pre-treatment outcomes
models_no_covariates = bind_rows(misinfo_binary_out, cs_risk_0)


```


```{r regressions_Col}

misinfo_outcomes_col = c('dissemination_f','dissemination_r','sharing_discernment',
                     'trust_sources_index_binary',
                     'trust_newspaper_binary','trust_gov_binary','trust_fb_binary',
                     'trust_tt_binary','trust_twitter_binary','trust_wa_binary')
misinfo_binary_col = paste0("%s ~ treatment")
## Regressions
misinfo_binary_out_col = foreach(i = 1:length(misinfo_outcomes_col), 
                                 .combine = "rbind") %do% {
    # Format formulas
    outcome = misinfo_outcomes_col[i]
    main_out = sprintf(misinfo_binary_col, outcome)

    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_colombia)

    # Tidy and return
    out = bind_rows(tidy(reg_full, conf.int=TRUE))
    return(out)
}


## Robustness checks 
### Removing 17.4% of inattentive respondents
misinfo_binary_robustness_out_col = foreach(i = 1:length(misinfo_outcomes_col), 
                                        .combine = "rbind") %do% {
    # Format formulas
    outcome = misinfo_outcomes_col[i]
    main_out = sprintf(misinfo_binary_col, outcome)
    
    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_colombia,
                         subset = attention_1_2 == 1)
    
    # Tidy and return
    out = bind_rows(tidy(reg_full, conf.int=TRUE))
    return(out)
}

```



## Figure 1
```{r fig.height=4, fig.width=8}
misinfo_p1 = models_no_covariates %>% 
    filter(outcome %in% c('a_ratings_true_e','a_ratings_false_e',
                          'accuracy_rate_e','accuracy_discernment_e'),
           term %in% c('misinformation_treatment1',
                       'misinformation_treatment2')) %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips')),
           outcome = factor(outcome, levels = c('accuracy_rate_e',
                                                'a_ratings_true_e',
                                                'a_ratings_false_e',
                                                'accuracy_discernment_e'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               nrow = 1,
               labeller = labeller(outcome=c(
                 'a_ratings_true_e'='Perceived\nAccuracy (A)',
                 'a_ratings_false_e'='Perceived\nAccuracy (F)',
                 'accuracy_rate_e'='Classification\nAccuracy',
                 'accuracy_discernment_e'='Accuracy Discernment\n(A - F)'
                 )
                 )
               ) 


misinfo_p2 = models_no_covariates %>% 
    filter(outcome %in% c('dissemination_f_e','dissemination_r_e',
                          'sharing_discernment_e'),
           term %in% c('misinformation_treatment1',
                       'misinformation_treatment2')) %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips')),
           outcome = factor(outcome, levels = c('dissemination_r_e',
                                                'dissemination_f_e',
                                                'sharing_discernment_e'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c(
                 'dissemination_f_e'='Sharing (F)',
                 'dissemination_r_e'='Sharing (A)',
                 'sharing_discernment_e'='Sharing Discernment\n(A - F)'
                 )
                 )
               )


misinfo_p1 + misinfo_p2 + plot_layout(ncol=1)

```

## Figure 2

```{r fig.height=2.5, fig.width=8}

s1_trust_index_plot = misinfo_binary_out %>% 
    filter(outcome == 'trust_sources_index_binary',
           term!='(Intercept)') %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c('trust_sources_index_binary'='Trust Sources'))) 




s1_trust_sources_plot = misinfo_binary_out %>% 
    filter(outcome %in% c('trust_gov_binary','trust_newspaper_binary','trust_fb_binary',
                          'trust_tt_binary','trust_twitter_binary','trust_wa_binary'),
           term!='(Intercept)') %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips')),
           outcome = factor(outcome, levels = c('trust_gov_binary','trust_newspaper_binary',
                                                'trust_fb_binary','trust_tt_binary',
                                                'trust_twitter_binary',
                                                'trust_wa_binary'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + 
    theme_bw() +
    theme( axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c('trust_gov_binary'='Gov.',
                                             'trust_newspaper_binary'='Newspapers',
                                             'trust_fb_binary'='Facebook',
                                             'trust_tt_binary'='TikTok',
                                             'trust_twitter_binary'='Twitter/X',
                                             'trust_wa_binary'='WhatsApp'))) 



s1_trust_index_plot + s1_trust_sources_plot + 
  plot_layout(ncol = 2, guides = 'collect')

```


## Figure 3

```{r fig.height=1.5, fig.width=6}

misinfo_binary_out_col %>%
    filter(outcome %in% c('dissemination_f',
                          'dissemination_r', 
                          'sharing_discernment'),
           term == 'treatment') %>%
    mutate(term = ifelse(term=='treatment', 'Tips', NA),
           outcome = factor(outcome, levels = c('dissemination_r',
                                                'dissemination_f',
                                                'sharing_discernment'))) %>%
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)),
                     size=2, force = 0) +
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c(
                 'dissemination_f'='Sharing (F)',
                 'dissemination_r'='Sharing (A)',
                 'sharing_discernment'='Sharing Discernment\n(A - F)'
                 )
                 )
               )

# difference between treatment effects (p = 0.02)
estimate_f = misinfo_binary_out_col %>% filter(outcome=='dissemination_f'
                                              & term=='treatment') %>% .$estimate
se_f = misinfo_binary_out_col %>% filter(outcome=='dissemination_f'
                                       & term=='treatment') %>% .$std.error

estimate_r = misinfo_binary_out_col %>% filter(outcome=='dissemination_r'
                                              & term=='treatment') %>% .$estimate
se_r = misinfo_binary_out_col %>% filter(outcome=='dissemination_r'
                                       & term=='treatment') %>% .$std.error

diff_t = estimate_f - estimate_r
se_diff_t = sqrt(se_f^2 + se_r^2)
z_v = diff_t/se_diff_t
# Z-test
p_values_z = 2*pnorm(-abs(z_v)) %>% round(2)
p_values_z
```

## Figure 4

```{r fig.height=2.5, fig.width=8}

s2_trust_index_plot = misinfo_binary_out_col %>% 
    filter(outcome == 'trust_sources_index_binary',
           term == 'treatment') %>% 
    mutate(term = ifelse(term=='treatment', 'Tips', NA)) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + 
    theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c('trust_sources_index_binary'='Trust Sources'))) 




s2_trust_sources_plot = misinfo_binary_out_col %>% 
    filter(outcome %in% c('trust_gov_binary','trust_newspaper_binary','trust_fb_binary',
                          'trust_tt_binary','trust_twitter_binary','trust_wa_binary'),
           term == 'treatment') %>% 
    mutate(term = ifelse(term=='treatment', 'Tips', NA),
           outcome = factor(outcome, levels = c('trust_gov_binary','trust_newspaper_binary',
                                                'trust_fb_binary','trust_tt_binary',
                                                'trust_twitter_binary',
                                                'trust_wa_binary'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + 
    theme_bw() +
    theme( axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c('trust_gov_binary'='Gov.',
                                             'trust_newspaper_binary'='Newspapers',
                                             'trust_fb_binary'='Facebook',
                                             'trust_tt_binary'='TikTok',
                                             'trust_twitter_binary'='Twitter/X',
                                             'trust_wa_binary'='WhatsApp'))) 



s2_trust_index_plot + s2_trust_sources_plot + plot_layout(ncol = 2, guides = 'collect')

```

# Online Appendix

## Figure A1

```{r}
params = expand_grid(n = seq(100, 500, by = 100), sd = seq(.2, .8, by = .2)) 

pwr_params = map_dfr(
    1:nrow(params),
    function(x){
        pwr_out <- power.t.test(n = params$n[x]*2, sd = params$sd[x], power = .8)
        broom::tidy(pwr_out) %>% 
            mutate(n = n/2) %>% 
            #mutate(n=n)
            return()
    }
)

pwr_params %>% 
    mutate(sd = paste0("SD of Outcome: ", sd)) %>%
    ggplot(aes(n, delta)) + 
    ggtitle('Power Analysis') +
    geom_point() + 
    geom_line() + 
    #ylim(c(0,.2)) +
    labs(x = "N per Group", y = "Minimum Detectable Effect") + 
    facet_wrap(~sd)

```

## Figure A4

```{r fig.height=9, fig.width=10}

# origin
origin = ggplot(dt_mexico, aes(x = origin)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Origin", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Colombia','Ecuador',
                                'El Salvador','Guatemala','Haiti',
                                'Honduras','Nicaragua','Peru','Venezuela','Other'))
# gender
gender = ggplot(dt_mexico, aes(x = as.factor(female))) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Sex", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels=c("0" = "Male",
                              "1" = "Female"))

# age
age = ggplot(dt_mexico, aes(x = age)) +    
    geom_histogram(aes(y = ..count../sum(..count..)), binwidth = 1) +
    labs(subtitle = "Age (in years)", x = '', y = 'Proportion') +
    geom_vline(data=dt_mexico, aes(xintercept=mean(age)),
               linetype="dashed", size=.5) +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) 


# education
education = ggplot(dt_mexico, aes(x = education_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Education", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('None','Incomplete primary','Complete primary',
                                'Incomplete secondary','Complete secondary',
                                'Incomplete college','Complete college',
                                'Postgraduate degree'))

# income
income = dt_mexico %>% 
    filter(income!=99) %>% 
    ggplot(., aes(x = as.factor(income))) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Do you have any steady source of income?", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels = c('0'='No', '1'='Yes'))


# Religion
religion = ggplot(dt_mexico, aes(x = religion_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Religion", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels = c('Catholic','Protestant',
                                'No Religion','Other'))

# Marital status
marital = ggplot(dt_mexico, aes(x = marital_status_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Marital Status", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('Single','Married','Free union','Separated','Widow'))

# destination
destination = ggplot(dt_mexico, aes(x = destination_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Expected Destination", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('USA','Canada','Spain','DK','Other'))

# temporary location
location = ggplot(dt_mexico, aes(x = location_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Temporary Location", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Mexico City','Tijuana','Ciudad Juárez',
                                'Mexicali','Matamoros','Tapachula','Piedras Negras','Other'))



origin + gender + age + education + religion + marital + income + 
    location + destination + plot_layout(ncol = 3, guides = 'collect')

```

## Figure A5

```{r fig.height=2.5, fig.width=6}

ggplot(dt_mexico, aes(x = cbp_knowledge_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "How much knowledge do you have of the CBP One digital application?", x = '', y = 'Proportion') +
    ylim(c(0,0.4)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('No knowledge','Little knowledge',
                                'Some knowledge','Full knowledge'))

```

## Figure A6

```{r height=1.5, fig.width=6}

dt_mexico %>% 
    filter(!is.na(social_desirability)) %>% 
    ggplot(., aes(x = as.factor(social_desirability))) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Have you ever fallen into the trap of fake news?", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels = c('0'='No', '1'='Yes'))

```

## Figure A7

```{r fig.height=7, fig.width=12}

newspapers = ggplot(dt_mexico, aes(x = outlet_newspaper_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    ylim(c(0,.5)) +
    labs(subtitle = "Newspapers", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Not at all','A little','Some','A lot'))

gov = ggplot(dt_mexico, aes(x = outlet_gov_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    ylim(c(0,.5)) +
    labs(subtitle = "Government Websites", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Not at all','A little','Some','A lot'))

fb = ggplot(dt_mexico, aes(x = outlet_fb_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    ylim(c(0,.5)) +
    labs(subtitle = "Facebook", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Not at all','A little','Some','A lot'))

wa = ggplot(dt_mexico, aes(x = outlet_wa_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    ylim(c(0,.5)) +
    labs(subtitle = "Groups on Whatsapp", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Not at all','A little','Some','A lot'))

tiktok = ggplot(dt_mexico, aes(x = outlet_tt_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    ylim(c(0,.5)) +
    labs(subtitle = "TikTok", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Not at all','A little','Some','A lot'))

tt = ggplot(dt_mexico, aes(x = outlet_twitter_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    ylim(c(0,.5)) +
    labs(subtitle = "X (Twitter)", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Not at all','A little','Some','A lot'))

newspapers + gov + fb + wa + tiktok + tt + plot_layout(ncol = 3) + 
    plot_annotation(title = 'How much you use these sources to obtain information on migration issues?')

```

## Figure A8

```{r fig.height=7, fig.width=8}

bullying1 = ggplot(dt_mexico, aes(x = cyberbullying1_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Impersonated you to send false information,\ninsult or assault other people", 
         x = '', y = 'Proportion') +
    ylim(c(0,1)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('No','Yes','DK/DA'))

bullying2 = ggplot(dt_mexico, aes(x = cyberbullying2_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Contacted you under false names to\nannoy or harm you", 
         x = '', y = 'Proportion') +
    ylim(c(0,1)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('No','Yes','DK/DA'))

bullying3 = ggplot(dt_mexico, aes(x = cyberbullying3_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Monitored your Internet sites or accounts to\ncause you discomfort or harm", 
         x = '', y = 'Proportion') +
    ylim(c(0,1)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('No','Yes','DK/DA'))

bullying4 = ggplot(dt_mexico, aes(x = cyberbullying4_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Made sexual advances or propositions\nthat upset you", 
         x = '', y = 'Proportion') +
    ylim(c(0,1)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('No','Yes','DK/DA'))

bullying5 = ggplot(dt_mexico, aes(x = cyberbullying5_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Published, distributed, exchanged or sold images, audios or videos of intimate sexual content,\nreal or simulated, of you without your consent", 
         x = '', y = 'Proportion') +
    ylim(c(0,1)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('No','Yes','DK/DA'))

bullying6 = ggplot(dt_mexico, aes(x = cyberbullying6_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Posted personal information, photos or\nvideos (fake or real) of you to harm you\n(excluding sexual content)", 
         x = '', y = 'Proportion') +
    ylim(c(0,1)) + 
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(limits = c('No','Yes','DK/DA'))

bullying1 + bullying2 + bullying3 + bullying4 + bullying5 + bullying6 +
    plot_layout(ncol = 2) + 
    plot_annotation(title = 'Indicate if, in the past year, someone used a cell phone or the internet to\nperform the following action:')

```


## Table A2

```{r}

tmp = dt_mexico %>%
    select(`Online risk perception`=online_risk_index_binary_e,
           `Pr(Implement tips)`=safety_measures_e,
           cybersecurity_treatment) %>%
    mutate(cybersecurity_treatment = case_when(cybersecurity_treatment==0 ~ 'Placebo',
                                               cybersecurity_treatment==1 ~ 'Tips',
                                               TRUE ~ NA_character_)) 
datasummary_balance(~cybersecurity_treatment, 
                    data = tmp,
                    fmt = 3,
                    stars = T,
                    dinm = F,
                    title = 'Outcome Variables (Cybersecurity) - Summary Statistics by Experimental Condition.\\label{tab:outcomes_summary_mx_cs}',
                    escape = FALSE
                    #output="tables/s1_summary_outcomes_cs.tex"
) 

```


## Table A3

```{r}


tmp = dt_mexico %>%
    select(misinformation_treatment,
           `Perceived accuracy (b)`=accuracy_rate_b,
           `Perceived accuracy (F) (b)`=a_ratings_false_b,
           `Perceived accuracy (A) (b)`=a_ratings_true_b,
           `Accuracy discernment (b)`=accuracy_discernment_b,
           `Verification (b)`=accuracy_verification_tendency_rate_b,
           `Accuracy verification (b)`=verification_tendency_rate_b,
           `Sharing (F) (b)`=dissemination_f_b,
           `Sharing (A) (b)`=dissemination_r_b,
           `Sharing discernment (b)`=sharing_discernment_b,
           `Perceived accuracy`=accuracy_rate_e,
           `Perceived accuracy (F)`=a_ratings_false_e,
           `Perceived accuracy (A)`=a_ratings_true_e,
           `Accuracy discernment`=accuracy_discernment_e,
           `Verification`=accuracy_verification_tendency_rate_e,
           `Accuracy verification`=verification_tendency_rate_e,
           `Sharing (F)`=dissemination_f_e,
           `Sharing (A)`=dissemination_r_e,
           `Sharing discernment`=sharing_discernment_e,
           `Trust sources`=trust_sources_index_binary,
           `Trust newspapers`=trust_newspaper_binary,
           `Trust gov.`=trust_gov_binary,
           `Trust Facebook`=trust_fb_binary,
           `Trust TikTok`=trust_tt_binary,
           `Trust Twitter/X`=trust_twitter_binary,
           `Trust WhatsApp`=trust_wa_binary) %>%
    mutate(misinformation_treatment = case_when(misinformation_treatment==0 ~ 'Placebo',
                                                misinformation_treatment==1 ~ 'Tips',
                                                misinformation_treatment==2 ~ 'Tips + ex.',
                                                TRUE ~ NA_character_))  

datasummary_balance(~misinformation_treatment, 
                    data = tmp,
                    fmt = 3,
                    stars = T,
                    dinm = F,
                    title = 'Outcome Variables (Misinformation) - Summary Statistics by Experimental Condition.\\label{tab:outcomes_summary_mx_misinfo}',
                    escape = FALSE,
                    #output="tables/s1_summary_outcomes_misinfo.tex",
                    notes = 'Note: (b) indicates that the variable was measured at baseline, i.e., pre-treatment. Otherwise, the variable was measured post-treatment.') 


```

## Table A4

```{r}

covariates_renamed = c('misinformation_treatment_tips' = 'misinformation_treatment_tips',
                       'misinformation_treatment_tips_ex' = 'misinformation_treatment_tips_ex',
                       'cybersecurity_treatment'='cybersecurity_treatment',
                       'female' = 'Female',
                       'income' = 'Income',
                       'education_clean' = 'Education',
                       'age' = 'Age',
                       'catholic' = 'Catholic',
                       'children_binary' = 'Has children',
                       'single' = 'Single',
                       'destination_US' = 'Destination = US',
                       'digital_literacy_binary' = 'Digital literacy',
                       'value_democracy_binary' = 'Value democracy')


##
s1_balance_1 = dt_mexico %>%
    select(all_of(names(covariates_renamed))) %>%
    rename_with(~ covariates_renamed[.x], 
                .cols = all_of(names(covariates_renamed))) %>% 
    mutate(treatment = ifelse(misinformation_treatment_tips==0, 
                              'Placebo','Tips') %>% 
               factor(., levels = c('Placebo','Tips')))

datasummary_balance(~treatment,
                    data = s1_balance_1 %>% 
                        select(-c(misinformation_treatment_tips,
                                  misinformation_treatment_tips_ex,
                                  cybersecurity_treatment)),
                    fmt = 3,
                    stars = T,
                    dinm_statistic = "p.value",
                    title = 'Balance Table (Study 1) - Placebo vs Tips') 


```

## Table A5

```{r}

s1_balance_2 = dt_mexico %>%
    select(all_of(names(covariates_renamed))) %>%
    rename_with(~ covariates_renamed[.x], 
                .cols = all_of(names(covariates_renamed))) %>%
    mutate(treatment = ifelse(misinformation_treatment_tips_ex==0, 
                              'Placebo','Tips + Example') %>% 
               factor(., levels = c('Placebo','Tips + Example')))

datasummary_balance(~treatment,
                    data = s1_balance_2 %>%
                        select(-c(misinformation_treatment_tips_ex,
                                  misinformation_treatment_tips,
                                  cybersecurity_treatment)),
                    fmt = 3,
                    stars = T,
                    dinm_statistic = "p.value",
                    title = 'Balance Table (Study 1) - Placebo vs Tips + Example')


```

## Table A6

```{r}

s1_balance_3 = dt_mexico %>%
    select(all_of(names(covariates_renamed))) %>%
    rename_with(~ covariates_renamed[.x], 
                .cols = all_of(names(covariates_renamed))) %>% 
    mutate(treatment = ifelse(cybersecurity_treatment==0, 
                              'Placebo','Tips Cybersecurity') %>% 
               factor(., levels = c('Placebo','Tips Cybersecurity')))

datasummary_balance(~treatment,
                    data = s1_balance_3 %>% 
                        select(-c(misinformation_treatment_tips_ex,
                                  misinformation_treatment_tips,
                                  cybersecurity_treatment)),
                    fmt = 3,
                    stars = T,
                    dinm_statistic = "p.value",
                    title = 'Balance Table (Study 1) - Placebo vs Tips Cybersecurity')

```


## Figure A11

```{r fig.height=2, fig.width=6}

misinfo_binary_out2 %>% 
    filter(outcome %in% c('verification_tendency_rate_e', 
                          'accuracy_verification_tendency_rate_e'),
           term %in% c('misinformation_treatment1',
                       'misinformation_treatment2')) %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips')),
           outcome = factor(outcome, 
                            levels = c('verification_tendency_rate_e',
                                       'accuracy_verification_tendency_rate_e'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c(
                   'verification_tendency_rate_e'='Verification',
                   'accuracy_verification_tendency_rate_e'='Accuracy Verification'))) 

```


## Figure A12

```{r}

p1 = misinfo_binary_out2 %>% 
    filter(outcome %in% c('a_ratings_true_e','a_ratings_false_e',
                          'accuracy_rate_e','accuracy_discernment_e'),
           term %in% c('misinformation_treatment1',
                       'misinformation_treatment2')) %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips')),
           outcome = factor(outcome, levels = c('accuracy_rate_e',
                                                'a_ratings_true_e',
                                                'a_ratings_false_e',
                                                'accuracy_discernment_e'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               nrow = 1,
               labeller = labeller(outcome=c(
                   'a_ratings_true_e'='Perceived\nAccuracy (A)',
                   'a_ratings_false_e'='Perceived\nAccuracy (F)',
                   'accuracy_rate_e'='Classification\nAccuracy',
                   'accuracy_discernment_e'='Accuracy Discernment\n(A - F)')))

p2 = misinfo_binary_out2 %>% 
    filter(outcome %in% c('dissemination_f_e','dissemination_r_e',
                          'sharing_discernment_e'),
           term %in% c('misinformation_treatment1',
                       'misinformation_treatment2')) %>% 
    mutate(term = factor(term, levels = c('misinformation_treatment2',
                                          'misinformation_treatment1'),
                         labels = c('Tips + example',
                                    'Tips')),
           outcome = factor(outcome, levels = c('dissemination_r_e',
                                                'dissemination_f_e',
                                                'sharing_discernment_e'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c(
                   'dissemination_f_e'='Sharing (F)',
                   'dissemination_r_e'='Sharing (A)',
                   'sharing_discernment_e'='Sharing discernment\n(A - F)')))


p1 + p2 + plot_layout(ncol=1)


```


## Figure A13

```{r fig.height=2, fig.width=6}

cs_treatment_out %>% 
    filter(term!='(Intercept)' & term!='online_risk_index_binary_b') %>% 
    mutate(term = case_when(
        term=='cybersecurity_treatment' ~ 'Tips\n(online privacy)')) %>%
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c(
                   'online_risk_index_binary_e'='Online Risk Perception',
                   'safety_measures_e'='Pr(Implement Tips)'))) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0)  

```


## Table A1

```{r results='asis'}
s1_kpi = data.frame(kpi = c("Expenditure (USD)",
                            "Eligibility rate",
                            "Clicks",
                            "Cost per click (USD)",
                            "Total surveys",
                            "Cost per survey (USD)",
                            "Effective surveys (EF)",
                            "Cost per EF (USD)",
                            "Uncompleted surveys",
                            "Non-effective surveys",
                            "Click-Through Rate (CTR) EF"),
                    result = c(5118.91,
                               0.2264,
                               11883,
                               0.36,
                               2690,
                               1.62,
                               1872,
                               2.32,
                               54,
                               764,
                               0.158))

kbl(s1_kpi, 
    'latex',
    caption = 'Study 1 - Key Performance Indicators',
    digits = 2,
    col.names =  c("KPI", "Result"), 
    position = 'H', 
    escape = F,
    label = 's1_kpi') %>% 
    add_footnote(., 
                 "Note: The Facebook campaign ran from March 6 to April 9, 2024.",
                 notation = "none",
                 escape = F)
```


## Table A7

```{r results='asis'}

misinfo_outcomes_hte = c('accuracy_rate_e',
                         'accuracy_discernment_e',
                         'a_ratings_true_e',
                         'a_ratings_false_e',
                         'dissemination_r_e',
                         'dissemination_f_e',
                         'sharing_discernment_e')



model_names = c("\\shortstack{Classification\\\\Accuracy}",
                "\\shortstack{Perceived\\\\Accuracy\\\\(A)}",           
                "\\shortstack{Perceived\\\\Accuracy\\\\(F)}",
                "\\shortstack{Accuracy\\\\Discernment\\\\(A - F)}",
                "\\shortstack{Sharing\\\\(A)}",
                "\\shortstack{Sharing\\\\(F)}",
                "\\shortstack{Sharing\\\\Discernment\\\\(A - F)}")

misinfo_binary = paste0("%s ~ misinformation_binary*motivated_reasoning_binary")
regression_list = list()
misinfo_subgroup = foreach(i = 1:length(misinfo_outcomes_hte), 
                           .combine = "rbind") %do% {
                               # Format formulas
                               outcome = misinfo_outcomes_hte[i]
                               main_out = sprintf(misinfo_binary, outcome)
                               
                               # Regressions
                               reg_full = lm_robust(as.formula(main_out), dt_mexico)
                               
                               # Tidy and return
                               regression_list[[i]] = reg_full
                               return(regression_list)
                           }

#reg table
texreg(regression_list,
       #file = 'tables/s1_hte_motivated_reasoning.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of treatment (Tips or Tips + Example) by level of motivated reasoning",
       label = "table:s1_hte_motivated_reasoning",
       custom.model.names = model_names,
       custom.coef.map = list(
           "(Intercept)"="Placebo",
           "misinformation_binary"="Treat. (T)",
           "motivated_reasoning_binary"="Reas. (Z)",
           "misinformation_binary:motivated_reasoning_binary"="T x Z"),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.")


```


## Table A8


```{r results='asis'}

misinfo_binary = paste0("%s ~ misinformation_binary*trust_people_binary")
regression_list = list()
misinfo_subgroup = foreach(i = 1:length(misinfo_outcomes_hte), 
                           .combine = "rbind") %do% {
                               # Format formulas
                               outcome = misinfo_outcomes_hte[i]
                               main_out = sprintf(misinfo_binary, outcome)
                               
                               # Regressions
                               reg_full = lm_robust(as.formula(main_out), dt_mexico)
                               
                               # Tidy and return
                               regression_list[[i]] = reg_full
                               return(regression_list)
                           }

#reg table
texreg(regression_list,
       #file = 'tables/s1_hte_trust.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of treatment (Tips or Tips + Example) by level of trust in people",
       label = "table:s1_hte_trust",
       custom.model.names = model_names,
       custom.coef.map = list(
           "(Intercept)"="Placebo",
           "misinformation_binary"="Treat. (T)",
           "trust_people_binary"="Trust (Z)",
           "misinformation_binary:trust_people_binary"="T x Z"),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.")



```


## Table A9

```{r results='asis'}

misinfo_binary = paste0("%s ~ misinformation_binary*digital_literacy_binary")
regression_list = list()
misinfo_subgroup = foreach(i = 1:length(misinfo_outcomes_hte), 
                           .combine = "rbind") %do% {
                               # Format formulas
                               outcome = misinfo_outcomes_hte[i]
                               main_out = sprintf(misinfo_binary, outcome)
                               
                               # Regressions
                               reg_full = lm_robust(as.formula(main_out), dt_mexico)
                               
                               # Tidy and return
                               regression_list[[i]] = reg_full
                               return(regression_list)
                           }

#reg table
texreg(regression_list,
       #file = 'tables/s1_hte_literacy.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of treatment (Tips or Tips + Example) by level of digital literacy",
       label = "table:s1_hte_literacy",
       custom.model.names = model_names,
       custom.coef.map = list(
           "(Intercept)"="Placebo",
           "misinformation_binary"="Treat. (T)",
           "digital_literacy_binary"="Dig. lit. (Z)",
           "misinformation_binary:digital_literacy_binary"="T x Z"),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.")


```


## Table A10

```{r results='asis'}

misinfo_binary = paste0("%s ~ misinformation_binary*female")
regression_list = list()
misinfo_subgroup = foreach(i = 1:length(misinfo_outcomes_hte), 
                           .combine = "rbind") %do% {
                               # Format formulas
                               outcome = misinfo_outcomes_hte[i]
                               main_out = sprintf(misinfo_binary, outcome)
                               
                               # Regressions
                               reg_full = lm_robust(as.formula(main_out), dt_mexico)
                               
                               # Tidy and return
                               regression_list[[i]] = reg_full
                               return(regression_list)
                           }

#reg table
texreg(regression_list,
       #file = 'tables/s1_hte_sex.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of treatment (Tips or Tips + Example) by sex (female)",
       label = "table:s1_hte_sex",
       custom.model.names = model_names,
       custom.coef.map = list(
           "(Intercept)"="Placebo",
           "misinformation_binary"="Treat. (T)",
           "female"="Female (Z)",
           "misinformation_binary:female"="T x Z"),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.")


```

## Figure B15

```{r fig.height=9, fig.width=10}

origin = ggplot(dt_colombia, aes(x = origin)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Origin", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Ecuador',
                                'El Salvador','Guatemala','Haiti',
                                'Honduras','Mexico','Nicaragua','Peru','Venezuela','Other'))
# gender
gender = ggplot(dt_colombia, aes(x = as.factor(female))) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Sex", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels=c("0" = "Male",
                              "1" = "Female"))

# age
age = ggplot(dt_colombia, aes(x = age)) +    
    geom_histogram(aes(y = ..count../sum(..count..)), binwidth = 1) +
    labs(subtitle = "Age (in years)", x = '', y = 'Proportion') +
    geom_vline(data=dt_colombia, aes(xintercept=mean(age)),
               linetype="dashed", size=.5) +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) 


# education
education = ggplot(dt_colombia, aes(x = education_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Education", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('None','Incomplete primary','Complete primary',
                                'Incomplete secondary','Complete secondary',
                                'Incomplete college','Complete college',
                                'Postgraduate degree'))
# income
income = dt_colombia %>% 
    filter(income!=99) %>% 
    ggplot(., aes(x = as.factor(income))) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Do you have any steady\nsource of income?", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels = c('0'='No', '1'='Yes'))


# Religion
religion = ggplot(dt_colombia, aes(x = religion_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Religion", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11)) +
    scale_x_discrete(labels = c('Catholic','Protestant',
                                'No Religion','Other'))

# Marital status
marital = ggplot(dt_colombia, aes(x = marital_status_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Marital Status", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('Single','Married','Free union','Separated','Widow'))

# destination
destination = ggplot(dt_colombia, aes(x = destination_descriptive)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Expected Destination", x = '', y = 'Proportion') +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_x_discrete(limits = c('USA','Canada','Spain','Latin America',
                                'DK','Other'))

origin + gender + age + education + religion + marital + income + 
    destination + plot_layout(ncol = 2, guides = 'collect')

```


## Figure B16

```{r fig.height=3.5, fig.width=7}

# info outlet
outlet_col = ggplot(dt_colombia, aes(x = info_outlet_all)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Top 3 Platforms", x = '', y = 'Proportion') +
    ylim(c(0,.5)) +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1))

# info source
source_col = ggplot(dt_colombia, aes(x = info_source_all)) +    
    geom_bar(aes(y = ..count../sum(..count..))) +
    labs(subtitle = "Top 3 Sources", x = '', y = 'Proportion') +
    ylim(c(0,.5)) +
    theme(panel.background = element_blank(),
          panel.border = element_rect(colour = "gray50", fill=NA, size=.11),
          axis.text.x = element_text(angle = 45, hjust = 1))


outlet_col + source_col + plot_layout(ncol = 2)

```


## Table B11

```{r results='asis'}

s2_kpi = data.frame(kpi = c("Expenditure (USD)",
                            "Eligibility rate",
                            "Clicks",
                            "Cost per click (USD)",
                            "Total surveys",
                            "Cost per survey (USD)",
                            "Effective surveys (EF)",
                            "Cost per EF (USD)",
                            "Non-effective surveys",
                            "Click-Through Rate (CTR) EF"),
                    result = c(3507.95,
                               0.0881,
                               27976,
                               0.12,
                               2465,
                               1.34,
                               709,
                               4.65,
                               1756,
                               0.013))

kbl(s2_kpi, 
    'latex',
    caption = 'Study 2 - Key Performance Indicators',
    digits = 2,
    col.names =  c("KPI", "Result"), 
    position = 'H', 
    escape = F,
    label = 's2_kpi') %>% 
    add_footnote(., 
                 "Note: The Facebook campaign ran from July 26 to September 1, 2024.",
                 notation = "none",
                 escape = F)

```


## Table B12

```{r}

tmp = dt_colombia %>%
    select(treatment,
           `Sharing (F)`=dissemination_f,
           `Sharing (A)`=dissemination_r,
           `Sharing discernment`=sharing_discernment,
           `Trust sources`=trust_sources_index_binary,
           `Trust newspapers`=trust_newspaper_binary,
           `Trust gov.`=trust_gov_binary,
           `Trust Facebook`=trust_fb_binary,
           `Trust TikTok`=trust_tt_binary,
           `Trust Twitter/X`=trust_twitter_binary,
           `Trust WhatsApp`=trust_wa_binary) %>%
    mutate(treatment = case_when(treatment==0 ~ 'Placebo',
                                 treatment==1 ~ 'Tips',
                                 TRUE ~ NA_character_))
datasummary_balance(~treatment, 
                          data = tmp,
                          fmt = 3,
                          stars = T,
                          dinm = F,
                          title = 'Outcome Variables - Summary Statistics by Experimental Condition.\\label{tab:outcomes_summary_col_misinfo}',
                          escape = FALSE) 

```


## Table B13

```{r}

s2_balance_1 = dt_colombia %>%
    select(treatment,
           Female = female,
           Income = income,
           Education = education_num,
           Age = age,
           Catholic = catholic,
           `Has children` = children_binary,
           Single = single,
           `Destination = US` = destination_US,
           `Value democracy` = value_democracy_binary) %>%
    mutate(treatment = ifelse(treatment==0, 'Placebo','Tips') %>% 
               factor(., levels = c('Placebo','Tips')))

datasummary_balance(~treatment,
                    data = s2_balance_1,
                    fmt = 3,
                    stars = T,
                    dinm_statistic = "p.value",
                    title = 'Balance Table (Study 2) - Placebo vs Tips.\\label{tab:balance_colombia}',
                    escape = FALSE) 

```

## Figure B18

```{r fig.height=1.5, fig.width=6}

misinfo_binary_robustness_out_col %>% 
    filter(outcome %in% c('dissemination_f',
                          'dissemination_r',
                          'sharing_discernment'),
           term == 'treatment') %>% 
    mutate(term = ifelse(term=='treatment', 'Tips', NA),
           outcome = factor(outcome, levels = c('dissemination_r',
                                                'dissemination_f',
                                                'sharing_discernment'))) %>% 
    ggplot(aes(y=estimate, x=term)) +
    geom_point() + theme_bw() +
    geom_errorbar(aes(ymin=conf.low, ymax=conf.high), width=0.1) +
    coord_flip() +
    labs(x="", y="ATE") +
    #ylim(-.4, .4) +
    geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
    geom_label_repel(aes(label = sprintf("%.3f", estimate)), 
                     size=2, force = 0) + 
    facet_wrap(. ~ outcome,
               labeller = labeller(outcome=c(
                   'dissemination_r'='Sharing (A)',
                   'dissemination_f'='Sharing (F)',
                   'sharing_discernment'='Sharing Discernment\n(A - F)'))) 


```


## Table B14

```{r}

# compare effect on FB vs other platforms
trust_outcome = c('trust_gov_binary',
                  'trust_newspaper_binary',
                  'trust_tt_binary',
                  'trust_twitter_binary',
                  'trust_wa_binary')

s2_trust = foreach(i = 1:length(trust_outcome), .combine = 'bind_rows') %do% {
    #
    tmp = trust_outcome[i]
    outcome = misinfo_binary_out_col %>%
        filter(outcome==tmp & term=='treatment') %>%
        .$estimate
    se = misinfo_binary_out_col %>%
        filter(outcome==tmp & term=='treatment') %>%
        .$std.error
    outcome_fb = misinfo_binary_out_col %>%
        filter(outcome=='trust_fb_binary' & term=='treatment') %>%
        .$estimate
    se_fb = misinfo_binary_out_col %>%
        filter(outcome=='trust_fb_binary' & term=='treatment') %>%
        .$std.error
    
    # Difference
    d = outcome_fb - outcome
    se_d = sqrt(se_fb^2 + se^2)
    z_v = d/se_d
    p = 2*pnorm(-abs(z_v)) %>% round(3)
    
    out = data.frame(source = tmp,
                     diff = round(d, 3),
                     se = round(se_d, 3),
                     p = round(p, 3))
    return(out)
}

s2_trust= s2_trust %>%
    mutate(Source = c('Gov.',
                      'Newspapers',
                      'TikTok',
                      'Twitter/X',
                      'WhatsApp')) %>%
    select(Source, diff, se, p)

kbl(s2_trust,
    'latex',
    caption = 'Average Treatment Effects on Trust: Facebook vs. Other Sources',
    digits = 3,
    col.names =  c("Source",
                   "$\\beta_{\\text{Facebook}} - \\beta_{\\text{Source}}$",
                   "$SE_{\\text{Diff}}$",
                   "$p_{\\text{Diff}}$"),
    position = 'H',
    escape = F,
    label = 's2_trust_diff') %>%
    add_footnote(.,
                 "Note: $\\beta_{\\text{Facebook}}$ is -0.105 (0.038).",
                 notation = "none",
                 escape = F)

```


## Table C15

```{r regression_tables_mx}

misinfo_binary = paste0("%s ~ misinformation_treatment")
s1_outcomes_tab = c('accuracy_rate_e',
                    'dissemination_f_e',
                    'dissemination_r_e',
                    'trust_sources_index_binary',
                    'trust_newspaper_binary',
                    'trust_gov_binary',
                    'trust_fb_binary',
                    'trust_tt_binary',
                    'trust_twitter_binary',
                    'trust_wa_binary',
                    'accuracy_discernment_e',
                    'sharing_discernment_e',
                    'a_ratings_true_e',
                    'a_ratings_false_e') #14

regression_list = list()
s1_misinfo_tables = foreach(i = 1:length(s1_outcomes_tab), .combine = "rbind") %do% {
    # Format formulas
    outcome = s1_outcomes_tab[i]
    main_out = sprintf(misinfo_binary, outcome)
    
    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_mexico)
    
    # Add regression model to the list
    regression_list[[i]] = reg_full
    return(regression_list)
}


```



```{r results='asis'}

texreg(list(regression_list[[1]],
            regression_list[[13]],
            regression_list[[14]],
            regression_list[[11]],
            regression_list[[3]],
            regression_list[[2]],
            regression_list[[12]]),
       #file = 'tables/s1_results_without_covariates_misinfo.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatments on Accuracy and Sharing Outcomes (Study 1)",
       label = "table:s1_results_without_covariates_misinfo",
       custom.model.names = c("\\shortstack{Classification\\\\Accuracy}",
                              "\\shortstack{Perceived\\\\Accuracy\\\\(A)}",
                              "\\shortstack{Perceived\\\\Accuracy\\\\(F)}",
                              "\\shortstack{Accuracy\\\\Discernment\\\\(A - F)}",
                              "\\shortstack{Sharing\\\\(A)}",
                              "\\shortstack{Sharing\\\\(F)}",
                              "\\shortstack{Sharing\\\\Discernment\\\\(A - F)}"),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'misinformation_treatment1'='Tips',
                              'misinformation_treatment2'='Tips + example'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```

## Table C16

```{r regression tables MX with controls}
s1_outcomes = c('accuracy_rate_e',
                'verification_tendency_rate_e',
                'accuracy_verification_tendency_rate_e',
                'dissemination_f_e',
                'dissemination_r_e',
                'accuracy_discernment_e',
                'sharing_discernment_e',
                'a_ratings_true_e',
                'a_ratings_false_e') #9

regression_list = list()
misinfo_binary_out2_tab = foreach(i = 1:length(s1_outcomes), .combine = "rbind") %do% {
    # Format formulas
    outcome = s1_outcomes[i]
    control = baseline_outcomes2[i]
    main_out = sprintf(misinfo_binary2, outcome, control)
    
    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_mexico)
    
    # Tidy and return
    # Add regression model to the list
    regression_list[[i]] = reg_full
    return(regression_list)
}
```


```{r results='asis'}

texreg(list(regression_list[[1]],
            regression_list[[8]],
            regression_list[[9]],
            regression_list[[6]],
            regression_list[[5]],
            regression_list[[4]],
            regression_list[[7]]),
       #file = 'tables/s1_misinfo_main_results.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatments on Accuracy, Accuracy discernment, Sharing, and Sharing discernment, controlling for outcomes measured at baseline (Study 1)",
       label = "table:s1_misinfo_main_results",
       custom.model.names = c("\\shortstack{Classification\\\\Accuracy}",
                              "\\shortstack{Perceived\\\\Accuracy\\\\(A)}",
                              "\\shortstack{Perceived\\\\Accuracy\\\\(F)}",
                              "\\shortstack{Accuracy\\\\Discernment\\\\(A - F)}",
                              "\\shortstack{Sharing\\\\(A)}",
                              "\\shortstack{Sharing\\\\(F)}",
                              "\\shortstack{Sharing\\\\Discernment\\\\(A - F)}"),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'misinformation_treatment1'='Tips',
                              'misinformation_treatment2'='Tips + example'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```


## Table C17
```{r results='asis'}

texreg(list(regression_list[[2]],regression_list[[3]]),
       #file = 'tables/s1_misinfo_main_results_2.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatments on Verification, controlling for outcomes measured at baseline (Study 1)",
       label = "table:s1_misinfo_main_results_2",
       custom.model.names = c("Verification",
                              "\\shortstack{Accuracy\\\\Verification}"),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'misinformation_treatment1'='Tips',
                              'misinformation_treatment2'='Tips + example'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")


```


## Table C18

```{r regression trust MX without controls}
misinfo_binary = paste0("%s ~ misinformation_treatment")
s1_outcomes_tab = c('trust_sources_index_binary',
                    'trust_gov_binary',
                    'trust_newspaper_binary',
                    'trust_fb_binary',
                    'trust_tt_binary',
                    'trust_twitter_binary',
                    'trust_wa_binary') 

regression_list = list()
s1_misinfo_tables = foreach(i = 1:length(s1_outcomes_tab), .combine = "rbind") %do% {
    # Format formulas
    outcome = s1_outcomes_tab[i]
    main_out = sprintf(misinfo_binary, outcome)
    
    # Regressions
    reg_full = lm_robust(as.formula(main_out), dt_mexico)
    
    # Add regression model to the list
    regression_list[[i]] = reg_full
    return(regression_list)
}

```


```{r results='asis'}

texreg(regression_list,
       #file = 'tables/s1_results_trust.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatments on Trust in Information Sources (Study 1)",
       label = "table:s1_trust",
       custom.model.names = c("Sources",
                              "Gov.",
                              "Newspapers",
                              "Facebook",
                              "TikTok",
                              "Twitter/X",
                              "WhatsApp"),
       custom.header = list('Trust'=1:7),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'misinformation_treatment1'='Tips',
                              'misinformation_treatment2'='Tips + example'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```


## Table C19
```{r results='asis'}

## Cybersecurity experiment
cs_risk_0 = lm_robust(online_risk_index_binary_e ~ cybersecurity_treatment,
                      dt_mexico)
cs_risk = lm_robust(online_risk_index_binary_e ~ cybersecurity_treatment 
                    + online_risk_index_binary_b, dt_mexico) 
cs_measures = lm_robust(safety_measures_e ~ cybersecurity_treatment, dt_mexico)

texreg(list(cs_risk_0, cs_risk, cs_measures),
       #file = 'tables/s1_cs.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Cybersecurity Treatment on Online Risk Perception (Study 1)",
       label = "table:s1_cs",
       custom.model.names = c('1','2','3'),
       custom.header = list('Online Risk Perception'=1:2,
                            'Pr(Implement Tips)'=3),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'cybersecurity_treatment'='Tips (online privacy)'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       custom.gof.rows = list("Baseline Outcome Adjustment"=c("No","Yes","No")),
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```


## Table C20

```{r regression_tables_col}

misinfo_outcomes = c('dissemination_f',
                     'dissemination_r',
                     'trust_sources_index_binary',
                     'trust_gov_binary',
                     'trust_newspaper_binary',
                     'trust_fb_binary',
                     'trust_tt_binary',
                     'trust_twitter_binary',
                     'trust_wa_binary',
                     'sharing_discernment')
misinfo_binary = paste0("%s ~ treatment")

## Regressions
regression_list = list()
misinfo_binary_out = foreach(i = 1:length(misinfo_outcomes), 
                             .combine = "rbind") %do% {
                                 # Format formulas
                                 outcome = misinfo_outcomes[i]
                                 main_out = sprintf(misinfo_binary, outcome)
                                 
                                 # Regressions
                                 reg_full = lm_robust(as.formula(main_out), dt_colombia)
                                 
                                 # Add regression model to the list
                                 regression_list[[i]] = reg_full
                                 return(regression_list)
                                 
                             }

```

```{r results='asis'}

texreg(list(regression_list[[2]],regression_list[[1]],regression_list[[10]]),
       #file = 'tables/s2_misinfo_main_results.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatment on Sharing and Sharing discernment (Study 2)",
       label = "table:s2_misinfo_main_results",
       custom.model.names = c("\\shortstack{Sharing\\\\(A)}",
                              "\\shortstack{Sharing\\\\(F)}",
                              "\\shortstack{Sharing\\\\Discernment\\\\(A - F)}"),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'treatment'='Tips'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       stars = c(0.01, 0.05, 0.1),
       threeparttable = T,
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```

## Table C21
```{r results='asis'}

texreg(list(regression_list[[3]],regression_list[[4]],regression_list[[5]],
            regression_list[[6]],regression_list[[7]],regression_list[[8]],
            regression_list[[9]]),
       #file = 'tables/s2_results_trust.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatment on Trust in Information Sources (Study 2)",
       label = "table:s2_trust",
       custom.model.names = c("Sources",
                              "Gov.",
                              "Newspapers",
                              "Facebook",
                              "TikTok",
                              "Twitter/X",
                              "WhatsApp"),
       custom.header = list('Trust'=1:7),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'treatment'='Tips'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = TRUE,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```


## Table C22
```{r results='asis'}

regression_list = list()
misinfo_binary_robustness_out = foreach(i = 1:length(misinfo_outcomes),
                                        .combine = "rbind") %do% {
                                            # Format formulas
                                            outcome = misinfo_outcomes[i]
                                            main_out = sprintf(misinfo_binary,
                                                               outcome)
                                            # Regressions
                                            reg_full = lm_robust(as.formula(main_out), dt_colombia,
                                                                 attention_1_2 == 1)
                                            
                                            # Add regression model to the list
                                            regression_list[[i]] = reg_full
                                            return(regression_list)
                                        }

texreg(list(regression_list[[2]],regression_list[[1]],regression_list[[10]]),
       #file = 'tables/s2_misinfo_results_robustness.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Effect of Misinformation Treatment on Sharing and Sharing discernment (Removing Inattentive Respondents) (Study 2)",
       label = "table:s2_misinfo_results_robustness",
       custom.model.names = c("\\shortstack{Sharing\\\\(A)}",
                              "\\shortstack{Sharing\\\\(F)}",
                              "\\shortstack{Sharing\\\\Discernment\\\\(A - F)}"),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'treatment'='Tips'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       threeparttable = T,
       stars = c(0.01, 0.05, 0.1),
       custom.note = "\\item %stars. Robust standard errors in parentheses.",
       fontsize = "scriptsize")

```


## Table C23
```{r results='asis'}

## Subgroup analysis 
misinfo_outcomes_sharing = c('dissemination_r',
                             'dissemination_f',
                             'sharing_discernment')

misinfo_interaction = paste0("%s ~ treatment*highly_educated")

## Regressions
regression_list = list()
misinfo_binary_out = foreach(i = 1:length(misinfo_outcomes_sharing), 
                             .combine = "rbind") %do% {
                                 # Format formulas
                                 outcome = misinfo_outcomes_sharing[i]
                                 main_out = sprintf(misinfo_interaction, outcome)
                                 
                                 # Regressions
                                 reg_full = lm_robust(as.formula(main_out), dt_colombia)
                                 
                                 # Add regression model to the list
                                 regression_list[[i]] = reg_full
                                 return(regression_list)
                             }


texreg(regression_list,
       #file = 'tables/s2_sharing_interaction.tex',
       caption.above = T,
       use.packages = FALSE,
       caption = "Heterogeneous Effects of Misinformation Treatment on Sharing and Sharing discernment (Study 2)",
       label = "table:s2_misinfo_results_interaction",
       custom.model.names = c("\\shortstack{Sharing\\\\(A)}",
                              "\\shortstack{Sharing\\\\(F)}",
                              "\\shortstack{Sharing\\\\Discernment\\\\(A - F)}"),
       custom.coef.map = list('(Intercept)'='Placebo',
                              'treatment'='Tips',
                              'highly_educated'='Education',
                              'treatment:highly_educated'='Tips x Education'),
       float.pos = "H",
       digits = 3,
       include.ci = FALSE,
       stars = c(0.01, 0.05, 0.1),
       threeparttable = T,
       custom.note = "\\item %stars.Robust standard errors in parentheses.",
       fontsize = "scriptsize")

# Education is a binary variable (1 if respondent has a bachelor's or postgraduate degree, 0 otherwise).

```